package com.zyx.thread4;

public class Childen extends Thread{
    private Kitchen kitchen;
    private int hp=0;//体力值
    private int health;//健康值

    public Childen(String name, Kitchen kitchen,int health) {
        super(name);
        this.kitchen = kitchen;
        this.health = health;
    }

    public void eat(){
        try {
            this.kitchen.do_eat();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void run() {
        //当体力值小于健康值的时候，需要吃饭
        while(this.hp<this.health){
            this.eat();
        }
        System.out.println(this.getName()+"吃饱了，谢谢妈妈！");
    }

    public Kitchen getKitchen() {
        return kitchen;
    }

    public void setKitchen(Kitchen kitchen) {
        this.kitchen = kitchen;
    }

    public int getHp() {
        return hp;
    }

    public void setHp(int hp) {
        this.hp = hp;
    }

    public int getHealth() {
        return health;
    }

    public void setHealth(int health) {
        this.health = health;
    }
}
